package mapstruct;

import DTO.PeopleDTO;
import DTO.UserDTO;
import PO.User;
import PO.UserGeo;
import PO.UserRole;
import PO.UserType;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @ProjectName: util
 * @Package: mapstruct
 * @ClassName: ${TYPE_NAME}
 * @Description:
 * @Author: haifeng.mi
 * @CreateDate: 2018/9/21 10:51
 * @UpdateUser: haifeng.mi
 * @UpdateDate: 2018/9/21 10:51
 * @UpdateRemark: The modified content
 * @Version: 1.0
 * Copyright: Copyright (c) 2018
 */
@Mapper
public interface UserInfoMapper {

    public static UserInfoMapper MAPPER = Mappers.getMapper(UserInfoMapper.class);


    /**
     * PO转DTO
     * 多个PO转成一个DTO
     * 设置UserType PO中的一个字段到UserDTO中
     * @param user
     * @return
     */
    @Mappings({
            @Mapping(target = "userGeo",  ignore = true),
            @Mapping(target = "userRoleList",  ignore = true),
            @Mapping(target = "type", source = "userType.type"),
            @Mapping(target = "userLoginId", source = "user.userLoginId")
    })
    UserDTO userToUserDTO(final User user, final UserType userType);

    /**
     * PO转DTO
     * 多个PO转成一个DTO
     * @param user
     * @return
     */
    @Mappings({
            @Mapping(target = "userLoginId", source = "user.userLoginId"),
            @Mapping(target = "type", ignore = true),
            @Mapping(target = "userRoleList",  ignore = true)
    })
    UserDTO userToUserDTO(final User user, final UserGeo userGeo);

    /**
     * PO转DTO
     * 多个PO转成一个DTO
     * userRoleList为DTO中的list
     * @param user
     * @return
     */
    @Mappings({
            @Mapping(target = "userLoginId", source = "user.userLoginId"),
            @Mapping(target = "type", ignore = true),
            @Mapping(target = "userGeo",  ignore = true)
    })
    UserDTO userToUserDTO(final User user, final List<UserRole> userRoleList);


}
